package cn.fz.event.describe;

import cn.fz.entity.User;
import cn.fz.event.publish.LoginApplicationEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

/**
 * ⑥通过@EventListener方式订阅消息，实现邮件业务处理，该种方式更加灵活，不用实现ApplicationListener接口
 */
@Service
public class MailNotifyListen {
    public void mailNotify(User user) {
        System.out.println("=======邮件业务======" + user);
    }

    @EventListener
    public void onLoginEvent(LoginApplicationEvent loginApplicationEvent) {
        System.out.println("===============收到登录通知事件===================");
        User user = (User) loginApplicationEvent.getSource();
        mailNotify(user);
    }
}
